from django.db import models
from Login.models import User

# Create your models here.
class UserProfile(models.Model):
    id = models.AutoField(primary_key=True, verbose_name="详情ID")
    # 关联到自定义的 User 模型
    user = models.OneToOneField(
        User,  # 修改为自定义的 User 模型
        on_delete=models.CASCADE,
        related_name='profile',
        verbose_name="关联用户"
    )
    gender_choices = [
        ('M', '男'),
        ('F', '女'),
    ]
    gender = models.CharField(
        max_length=1,
        choices=gender_choices,
        blank=True,
        null=True,
        verbose_name="性别"
    )
    birthdate = models.DateField(
        blank=True,
        null=True,
        verbose_name="生日"
    )
    # age = models.IntegerField(
    #     blank=True,
    #     null=True,
    #     verbose_name="年龄"
    # )
    # DECIMAL(5,2) 对应 Django 的 DecimalField
    # max_digits 是总位数，decimal_places 是小数位数
    height = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        blank=True,
        null=True,
        verbose_name="身高(cm)"
    )
    weight = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        blank=True,
        null=True,
        verbose_name="体重(kg)"
    )
    avatar_url = models.URLField(
        max_length=255,
        blank=True,
        null=True,
        verbose_name="头像地址"
    )
    is_realname = models.BooleanField(default=False, verbose_name="是否实名认证")
    realname = models.CharField(max_length=32, blank=True, null=True, verbose_name="实名姓名")
    id_number = models.CharField(max_length=32, blank=True, null=True, verbose_name="身份证号")
    class Meta:
        verbose_name = "用户详情"
        verbose_name_plural = "用户详情"



    def __str__(self):
        return f"{self.user.phone} 的个人资料"  # 修改为显示手机号